package userctr

import (
	"auusoft/AuuWiki/Models"
	//"fmt"
	"auusoft/AuuWiki/controllers"
)

type UserlistController struct {
	controllers.RootController
}

func (this *UserlistController) Get() {
	// users, _ := models.GetAllUserInfo()
	// //this.Data["Users"] = users

	// t := ""
	// for _, user := range users {
	// 	t = t + `<tr><td>`
	// 	t = t + user.UserName + `</td>`
	// 	t = t + `<td>` + strconv.FormatBool(user.Ifadmin) + `</td>`
	// 	t = t + `<td>`
	// 	t = t + `    <a href="/userctr/edituser/`
	// 	t = t + user.UserName
	// 	t = t + `"><i class="icon-pencil"></i></a>`
	// 	t = t + `    <a href="/userctr/deluser/`
	// 	t = t + user.UserName
	// 	t = t + `" role="button" data-toggle="modal"><i class="icon-remove"></i></a></td></tr>`
	// }
	// this.Data["tbl"] = beego.MarkDown(t)
	// //fmt.Printf("%s", len(users))
	this.Data["username"] = this.CheckSession()

	ifadmin := controllers.GetIfadmin()

	if ifadmin == "true" {
		this.Layout = "layout.html"
		this.TplNames = "userList.html"
	} else {
		this.Ctx.Redirect(302, "/")
	}

}

func (this *UserlistController) Post() {
	this.CheckSession()
	users, _ := models.GetAllUserInfo()
	//this.Data["Users"] = users

	t := ""
	for _, user := range users {
		t = t + `<tr><td>`
		t = t + user.UserName + `</td>`
		t = t + `<td>` + user.Ifadmin + `</td>`
		t = t + `<td>`
		t = t + `    <a href="/userctr/deluser/?usr=`
		t = t + user.UserName
		t = t + `" role="button" data-toggle="modal"><i class="icon-remove"></i></a></td></tr>`
	}
	this.Ctx.WriteString(t)
}
